<%--
    Document   : loanRequest
    Created on : 04 14, 11, 15:27:20 PM
    Author     : MonicaSandoval
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib  prefix="s" uri="/struts-tags" %>
<%@taglib  prefix="sj" uri="/struts-jquery-tags" %>
<%@taglib  prefix="sjg" uri="/struts-jquery-grid-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<div id="editrequest" style="width: 100%">
    <s:url id="remoteurl" action="editregister" includeParams="all" ></s:url>
    <s:url id="editurl" value="editcheck" />
    <s:url id="loanappurl" value="loanprofile-loanapp.jsp" />
    <script type="text/javascript" src="<s:url value='/struts/js/base/jquery.ui.datepicker.min.js'/>"></script>
        <script type="text/javascript">
            var rowId = 0;
            $.subscribe('editGrid', function(event,data) {
                if(rowId!=0){
                    $("#gridtable").jqGrid('editGridRow',rowId,{resize:true,drag:true,closeOnEscape:true,closeAfterEdit:true,jqModal:true,width:350,left:310,top:20,reloadAfterSubmit:false,afterSubmit:function(response, postdata) {return isError(response.responseText);}});
                }else{
                    alert("Please select a check first.");
                }
            });
            
            $(document).ready(function(){
                <c:set var="selected" value="${param.selected}" scope="session" />
            });

            $.subscribe("gridCompleteTopics",function() {                               
                document.getElementById("selected").value = $("#gridtable").jqGrid("getDataIDs"); 
            });
            
            $.subscribe('gridRowSelected', function(event,data) {
                rowId = event.originalEvent.id;
            });

            function formatLink(cellvalue, options, rowObject) {
                return "<a href='<s:property value="loanappurl" />?id="+rowObject["loanverificationid"]+"' onClick='javascript: return openDialog(this)'>" + cellvalue + "</a>";
            }
            function openDialog(e) {
                window.open(e.href, "newWindow");
                return false;
            }
            function proceedButton(){
                document.savereq.submit();
            }
            function cancelButton(){
                $('#dialog').dialog('close');
            }
            function noButton(){
                $('#dialog1').dialog('close');
            }
            function isError(text) {
                if(text.indexOf('ERROR') >= 0) { return [false, text]; }
                return [true,''];
            }
            function print(){
                window.open("/Cashmate/check.jsp?selected=" + $("#gridtable").jqGrid("getDataIDs"), "newWindow2"); 
            }
        </script>
        <p><sj:submit button="true" cssStyle="font-size:14px" id="grid_edit" onClickTopics="editGrid" value="Edit Check Info"/></p>
    <sjg:grid
        id="gridtable"
        caption="Edit Checks"
        dataType="json"
        href="%{remoteurl}"
        pager="true"
        autowidth="true"
        navigator="false"
        gridModel="gridModel"
        rowList="10,15,20"
        rowNum="15"
        rownumbers="true"
        onCompleteTopics="gridCompleteTopics"
        onSelectRowTopics="gridRowSelected"
        navigatorEditOptions="{height:280,reloadAfterSubmit:false}"
        editurl="%{editurl}"
        sortable="false"
        shrinkToFit="false"
    >
        <sjg:gridColumn name="loanverificationid" index="loanverificationid" title="Loan Verification No." hidedlg="true" hidden="true" /> 
        <sjg:gridColumn name="loanid"
                        index="loanid"
                        title="Loan No."
                        key="true"
                        hidedlg="true"
                        hidden="true"
        />        
        <sjg:gridColumn name="completename"
                        index="borrowername"
                        title="Borrower Name"
                        align="center"
                        editable="true"
        />
        <sjg:gridColumn name="areacode" 
                        index="area"
                        title="Area"
                        align="center"
        />
        <sjg:gridColumn name="netloanableamount" 
                        index="netloanableamount"
                        title="Check Amount"
                        align="right"
                        formatter="currency"
        />
        <sjg:gridColumn name="checkno" 
                        index="checkno"
                        title="Check No."
                        align="center"
                        editable="true"
                        edittype="text"
                        editrules="{required: true}"
        />
        <sjg:gridColumn name="bankaccountno" 
                        index="bankaccountno"
                        title="Bank Acct. No."
                        align="center"
                        editable="true"
                        edittype="text"
                        editrules="{required: true}"
        />
        <sjg:gridColumn name="loanverdocumentno" 
                        index="docno"
                        title="Loan Application"
                        formatter = "formatLink"
                        search="true"
                        align="center"
                        cssClass="gridlink"
                        width=""
        />
</sjg:grid>
<br/>
<c:if test="${param.error == 'yes'}">
    <hr />
    <p>
        Please fill up the bank accounts and check numbers of the checks.
    </p>
</c:if>

<hr/>
<br/>
<sj:dialog
    id="dialog"
    autoOpen="false"
    modal="false"
    title="Save Request"
>
    Are you sure you want to save the check register?
    <br />
      <s:form name="savereq" action="updatechecks">
        <s:textfield name="selected" id="selected" value="" cssStyle="display:none" />
   </s:form>
    <hr />
    <div style="text-align: center">
    <sj:a
    name="yes"
    id="yes"
    button="true"
    cssStyle="font-size:12px"
    onclick="proceedButton()"
    >
       Yes
    </sj:a>
 
   <sj:a
    name="no"
    id="no"
    openDialog="dialog"
    button="true"
    cssStyle="font-size:12px"
    >
       No
    </sj:a>
   <sj:a
    name="cancel"
    id="cancel"
    button="true"
    cssStyle="font-size:12px"
    onclick="cancelButton()"
    >
       Cancel
    </sj:a>
    </div>
</sj:dialog>
<sj:a
    name="createReq"
    id="createReq"
    openDialog="dialog"
    button="true"
    buttonIcon="ui-icon-disk"
>
   Save Check Register
</sj:a>

   <sj:a
    name="printButton"
    id="printButton"
    onclick="print()"
    button="true"
    buttonIcon="ui-icon-print"
>
   Print Checks
</sj:a>
   
<sj:dialog
    id="dialog1"
    autoOpen="false"
    modal="false"
    title="Exiting"
>
 Are you sure you don't want to save the check register?<br />
 <br/>
 <hr/>
 <div style ="text-align: center">
   <sj:a
    name="yes"
    id="yes"
    button="true"
    cssStyle="font-size:12px"
    href="/loanrelease.jsp?cat=check"
    >
       Yes
    </sj:a>
   <sj:a
    name="no2"
    id="no2"
    button="true"
    cssStyle="font-size:12px"
    onclick="noButton()"
    >
       No
    </sj:a>
 </div>
</sj:dialog>   
</div>
